﻿$(document).ready(function () {
    $("#btnAddSection").click(function () {
        //Invoke AJAX method to generate new password
        $.post(pathPrefix + "Albums/GeneratePassword", null, function (result) {
            var data = {
                "EditorPassword": result,
                "PagesCount": 2,
                "SectionTitle": "",
                "AlbumSectionTypeId": 2
            };

            $("#sectionRowTemplate").tmpl(data).appendTo("table#SectionsTable");

            $("#SectionsTable").hide();
            if ($("#SectionsTable tr").length > 1) {
                $("#SectionsTable").show();
            }

            tableAltRows();
        }, "json");
    });

    $(".removeSection").live("click", function () {
        var row = $(this).parents("tr");
        var albumSectionTypeId = row.tmplItem().data.AlbumSectionTypeId;

        //if not כריכה
        if (albumSectionTypeId != 1) {
            //remove the selected row
            row.next(".editorFormRow").remove();
            row.remove();

            $("#SectionsTable").data("RowsDeleted", true);

            if ($("#SectionsTable tr").length == 1) {
                $("#SectionsTable").hide();
            }
        }

        return false;
    });
});